﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DroidLord.Util
{
    class FileUtils
    {

        public static bool saveFile(String filePath, String text)
        {
            try
            {
                using (StreamWriter sw = new StreamWriter(filePath,false,System.Text.Encoding.UTF8))
                {
                    sw.WriteLine(text);
                    sw.Flush();
                    sw.Close();
                }
                return true;
            }catch(Exception eeee)
            {

            }
            return false;
        }
        public static  void   saveFileLine(String filePath,String text)
        {
            using (StreamWriter sw = new StreamWriter(filePath,false,System.Text.Encoding.UTF8))
            {
                sw.WriteLine(text);
                sw.Flush();
                sw.Close();
            }
        }
        public static HashSet<string> readLineFile(String filePath)
        {
            HashSet<string> liveInfoId = new HashSet<string>();
            if(!File.Exists(filePath))
            {
                return liveInfoId;
            }
            try
            {
                // 创建一个 StreamReader 的实例来读取文件 
                // using 语句也能关闭 StreamReader
                using (StreamReader sr = new StreamReader(filePath,System.Text.Encoding.UTF8))
                {
                    string line;
                    // 从文件读取并显示行，直到文件的末尾 
                    while ((line = sr.ReadLine()) != null)
                    {
                        liveInfoId.Add(line.Trim());
                    }
                }
            }
            catch (Exception e)
            {
                // 向用户显示出错消息
            }
            return liveInfoId;
        }



        public static string readAll(String filePath)
        {
            try
            {
               
                if (!File.Exists(filePath))
                {
                    return "";
                }
                return File.ReadAllText(filePath, Encoding.UTF8);
            }catch(Exception eeee)
            {

            }
            return "";
        }
    }
}
